﻿using System;

namespace winS.Unity
{
    /// <summary>
    /// 重复调用函数
    /// </summary>
    internal class RepeatCallFunction : Function
    {
        private float time;

        private readonly float interval;

        private readonly Action function;

        public RepeatCallFunction(float interval, Action function)
        {
            this.interval = interval;
            this.function = function;
        }

        internal override void Update(float deltaTime)
        {
            time += deltaTime;
            if (time < interval) return;
            time = 0f;
            function?.Invoke();
        }
    }
}